package capaDatos;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

import capaNegocio.PedidoCliente;



public class Serializacion {
	
	public static void persistenciaGuardar(ArrayList<PedidoCliente> listaPedidos2) {
		try{
			FileOutputStream fos = new FileOutputStream("pedidos.txt");
			ObjectOutputStream out = new ObjectOutputStream(fos);
			out.writeObject(listaPedidos2);
			out.close();
			
		}
		catch (Exception e){
			e.printStackTrace();
		}
	}
	
	
	@SuppressWarnings("unchecked")
	public static ArrayList<PedidoCliente> persistenciaRecuperar(){
		ArrayList<PedidoCliente> listaPedido = null;
		try{
			FileInputStream fis = new FileInputStream("pedidos.txt");
			ObjectInputStream in = new ObjectInputStream(fis);
			listaPedido = (ArrayList<PedidoCliente>) in.readObject();
			in.close();
			}
		
		catch (Exception e){
			e.printStackTrace();
		}
		
		return listaPedido;
		
	}
	
	
	

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
